﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FTchina.Api
{
    /// <summary>
    ///Email 的摘要说明
    /// </summary>
    public class Email
    {
        public Email()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 查看用户的邮件是否已读
        /// </summary>
        /// <returns></returns>
        public static Boolean ChkReadByEmailIDAndUserID(string emailid, string userid)
        {

            return shujuku.GetValueByKey("readed", "Email_UserList", "userid='" + userid + "' and emailid='" + emailid + "'") == "1";
        }


        /// <summary>
        /// 设置用户邮件为已读
        /// </summary>
        /// <param name="emailid"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static Boolean SetEmailReaded(string emailid, string userid)
        {
            return shujuku.ExecuteSql("update Email_UserList set readed=1 where userid='" + userid + "' and  emailid = '" + emailid + "'");
        }



        /// <summary>
        /// 通过email id 获取 附件Guid
        /// </summary>
        /// <param name="emailid"></param>
        /// <returns></returns>
        public static string GetAttchGuidByEmailId(string emailid)
        {
            return shujuku.GetValueByKey("attchid", "Email_attch", "emailid='" + emailid + "'");

        }




        /// <summary>
        /// 通过完整路径获取文件名
        /// </summary>
        /// <param name="fullpath">uploads/2011/4/28/4bc9353c658b435c829dbbd0146d20f600001XXXX.jpg</param>
        /// <returns>XXXX.jpg</returns>
        public static string GetFileNameByFullPath(string fullpath,bool hasguid)
        {
           
            string filename = fullpath.Split('/')[4];
            if (hasguid)
            {//文件名中带有guid编码则去掉
                filename = filename.Substring(32, filename.Length - 32);
            }

            return filename;
        }
    }
}